package now_coder.dp.ncs;

public class NC83 {

    public double maxProduct(double[] arr) {
        if (arr == null || arr.length == 0)
            return 0;

        double[] min = new double[arr.length];
        double[] max = new double[arr.length];
        min[0] = arr[0];
        max[0] = arr[0];
        double ans = arr[0];

        for (int i = 1; i < arr.length; i++) {
            if (arr[i] >= 0){
                max[i] = Math.max(max[i - 1] * arr[i], arr[i]);
                min[i] = Math.min(min[i - 1] * arr[i], arr[i]);
            }else {
                max[i] = Math.max(min[i - 1] * arr[i], arr[i]);
                min[i] = Math.min(max[i - 1] * arr[i], arr[i]);
            }
            ans = Math.max(max[i], ans);
        }

        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new NC83().maxProduct(new double[]{-2.5, 4, 0, 3, 0.5, 8, -1}));
    }

}
